<template>
    <div>
        <div style="height:30px;margin-top:3px">
            <Button type="primary" @click="createSs11002()" icon="md-add">录入家庭成员</Button>
            <ss11002-modal ref="ss11002Modal" @ok="reloadData"></ss11002-modal>
        </div>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       :data="tableData">
                <vxe-table-column field="azcp0003" title="户主姓名" align="center" width="100" fixed="left"/>
                <vxe-table-column field="azcp0001" title="证件号码" align="center" width="180" fixed="left"/>
                <vxe-table-column field="azcp0004_name" title="性别" align="center" width="60"/>
                <vxe-table-column field="azcp0005" title="出生日期" align="center" width="120"/>
                <vxe-table-column field="azcp0007_name" title="民族" align="center" width="100"/>
                <vxe-table-column field="azcp0517_name" title="与申请人关系" align="center" width="120"/>
                <vxe-table-column field="azcp0009_name" title="健康状况" align="center" width="150"/>
                <vxe-table-column field="azcp0502_name" title="劳动能力丧失情况" align="center" width="150"/>
                <vxe-table-column field="" title="操作" min-width="200" fixed="right">
                    <template v-slot="{ row }">
                        <Button type="warning" size="small" style="margin-right: 5px" @click="handleEdit(row)">编辑</Button>
                        <Button type="success" size="small" style="margin-right: 5px" @click="handleView(row)">详情</Button>
                        <Button type="error" size="small" style="margin-right: 5px" @click="handleDelete(row)">删除</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
        <div style="height:40px;line-height:40px;margin-top:10px;text-align: center ">
            <Button @click="prevStep">上一步</Button>
            <Button type="primary" @click="nextStep" :loading="btnLoading" style="margin-left:20px">下一步</Button>
        </div>
    </div>
</template>

<script>
    import ss11002Modal from './Ss11002Modal.vue'
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'

    export default {
        name: 'application2',
        mixins: [CommonMixin],
        components: {
            ss11002Modal,
        },
        data() {
            return {
                dataSs11002: {},
                url: {
                    list: '/api/ac/subsistence/ss02050Service/getFamilyMember',
                    delete: '/api/ac/subsistence/ss02050Service/deleteFamilyMember',
                    checkStep2: '/api/ac/subsistence/ss11002Service/checkPersonInfo',
                },
                dataCount: 0,
                pageSize: 10,
                familyInfo: {},
                queryParam: {},
                tableData: [],
                Loading: false,
                btnLoading: false,
            }
        },
        methods: {
            prevStep() {
                let that = this
                that.familyInfo.id = that.tableData[0].acfx0101
                this.$emit('prevStep',that.familyInfo)
            },
            nextStep() {
                let that = this
                this.$emit('nextStep',that.familyInfo)
            },
            handleEdit(row) {
                let that = this
                that.$refs.ss11002Modal.dataSs11002 = row
                that.$refs.ss11002Modal.validateStatus = false
                that.$refs.ss11002Modal.edit(row)
            },
            handleView(row) {
                let that = this
                that.$refs.ss11002Modal.dataSs11002 = row
                that.$refs.ss11002Modal.validateStatus = false
                that.$refs.ss11002Modal.view(row)
            },
            createSs11002() { // 录入保障人员
                let that = this
                that.$refs.ss11002Modal.create()
                that.$refs.ss11002Modal.validateStatus = false
                that.$refs.ss11002Modal.acfx0101 = that.tableData[0].acfx0101
            },
            handleDelete(row) {
                let that = this
                let record = row
                if (record.id) {
                    let isMaster = record.azcp0517
                    if (isMaster == '01') {
                        that.$Message.error('家庭户主不可删除')
                        return
                    } else {
                        this.$Modal.confirm({
                            title: '确定删除吗',
                            onOk: () => {
                                let url = that.url.delete
                                let dataParam = {}
                                dataParam.id = record.id
                                postAction(url, dataParam).then((res) => {
                                    if (res.data.data.code == 1) {
                                        that.$Message.success(res.data.data.msg)
                                        that.reloadData()
                                    } else {
                                        that.$Message.error(res.data.data.msg)
                                    }
                                });
                            },
                            onCancel: () => {
                            }
                        });
                    }

                } else {
                    that.$Message.error('请选择操作数据')
                }
            },
            reloadData() {
                let that = this
                that.queryParam.ss02050Id = that.familyInfo.id
                that.loadData()
            },
        },
        created() {
            let that = this
            that.familyInfo = that.$parent.$parent.familyInfo
            that.queryParam.ss02050Id = that.$parent.$parent.ss02050Id
            if ( that.queryParam.ss02050Id == undefined){
                that.queryParam.ss02050Id = that.familyInfo.id
            }
            this.loadData()
        },
    }
</script>

<style scoped>

</style>
